package com.rran.study.chat.ops.service.impl;

import com.alibaba.fastjson.JSON;
import com.rran.study.chat.common.model.Response;
import com.rran.study.chat.common.utils.FeignResultUtil;
import com.rran.study.chat.ops.client.UserClient;
import com.rran.study.chat.ops.service.UserService;
import com.rran.study.chat.user.client.UserApi;
import com.rran.study.chat.user.dto.request.LoginWithPwdDTO;
import com.rran.study.chat.user.dto.request.LoginWithSmsDTO;
import com.rran.study.chat.user.dto.request.QueryUserInfoDTO;
import com.rran.study.chat.user.dto.request.UserInfoDTO;
import com.rran.study.chat.user.dto.response.LoginVO;
import com.rran.study.chat.user.dto.response.UserInfoVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author yy
 * @Type UserServiceImpl.java
 * @Desc
 * @date 2020/8/11 11:49
 */
@Slf4j
@Service
public class UserServiceImpl implements UserService {


    @Autowired
    private UserClient userClient;

    @Autowired
    private FeignResultUtil feignResultUtil;

    @Override
    public Response<LoginVO> loginWithSms(LoginWithSmsDTO loginWithSmsDTO) {
        Response<LoginVO> result = userClient.loginWithSms(loginWithSmsDTO);
        log.info("用户短信登录result <==={}", JSON.toJSONString(result));
        feignResultUtil.checkResultCode(result.getCode(), result.getDescription());
        return result;
    }

    @Override
    public Response<LoginVO> loginWithPwd(LoginWithPwdDTO loginWithPwdDTO) {
        Response<LoginVO> result = userClient.loginWithPwd(loginWithPwdDTO);
        log.info("用户账号密码登录result <==={}", JSON.toJSONString(result));
        feignResultUtil.checkResultCode(result.getCode(), result.getDescription());
        return result;
    }

    @Override
    public Response<UserInfoVO> getUserInfo(QueryUserInfoDTO queryUserInfoDTO) {
        Response<UserInfoVO> result = userClient.getUserInfo(queryUserInfoDTO);
        log.info("获取用户信息result <==={}", JSON.toJSONString(result));
        feignResultUtil.checkResultCode(result.getCode(), result.getDescription());
        return result;
    }

    @Override
    public Response updateUserInfo(UserInfoDTO userInfoDTO) {
        //todo
        return null;
    }

}
